package com.bw.user.mvvm.view.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bw.mvvm_common.utils.IntentAction;
import com.bw.user.R;
import com.bw.user.adapter.ViewPagerAdapter;
import com.bw.user.mvvm.view.fragment.AllFragment;
import com.bw.user.mvvm.view.fragment.CancelFragment;
import com.bw.user.mvvm.view.fragment.OffFragment;
import com.bw.user.mvvm.view.fragment.PayMentFragment;
import com.bw.user.mvvm.view.fragment.WaitFragment;
import com.flyco.tablayout.SlidingTabLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

public class UserOrderActivity extends AppCompatActivity {

    private SlidingTabLayout userOrderTab;
    private ViewPager userOrderVip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_order);
        initView();
        EventBus.getDefault().register(this);
       String[] title = new String[]{"全部","代付款","待收货","已完成","已取消"};
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new AllFragment());
        fragments.add(new PayMentFragment());
        fragments.add(new WaitFragment());
        fragments.add(new OffFragment());
        fragments.add(new CancelFragment());
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
        userOrderVip.setAdapter(viewPagerAdapter);
        userOrderTab.setViewPager(userOrderVip,title);



    }

    @Subscribe(sticky = true)
    public void chexct(IntentAction intentAction){
        if(intentAction.ation.equals("payment")){
            userOrderVip.setCurrentItem(1);
        }else if(intentAction.ation.equals("wait")){
            userOrderVip.setCurrentItem(2);
        }else if(intentAction.ation.equals("off")){
            userOrderVip.setCurrentItem(3);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    private void initView() {
        userOrderTab = (SlidingTabLayout) findViewById(R.id.user_order_tab);
        userOrderVip = (ViewPager) findViewById(R.id.user_order_vip);
    }
}